//
//  ExaminaColumnView.m
//  Coach_HaiGeEr
//
//  Created by liuchen on 2018/10/17.
//  Copyright © 2018年 海格尔. All rights reserved.
//

#import "ExaminaColumnView.h"
#import "NetEasyTabView.h"
@interface ExaminaColumnView()<UIScrollViewDelegate>
@property (nonatomic,strong) NetEasyTabView *indicatorView;
@property (nonatomic,copy) NSArray *titleArr;
@end

@implementation ExaminaColumnView

- (instancetype)initWithFrame:(CGRect)frame WithTitle:(NSArray *)titleArr{
    self = [super initWithFrame:frame];
    if (self) {
        self.titleArr = titleArr;
        [self createSubView];
    }
    return self;
}

#pragma mark ==========创建视图==========
- (void)createSubView{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.indicatorView];
    
    UIScrollView *contentSrcView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.indicatorView.frame.size.height, self.frame.size.width, self.frame.size.height-self.indicatorView.frame.size.height)];
    contentSrcView.contentSize = CGSizeMake(self.frame.size.width*self.titleArr.count, self.frame.size.height-self.indicatorView.frame.size.height);
    contentSrcView.pagingEnabled = YES;
    contentSrcView.delegate = self;
    contentSrcView.bounces = NO;
    contentSrcView.backgroundColor = [UIColor colorWithHexString:@"#eeeeee"];
    _contentSrcView = contentSrcView;
    [self addSubview:self.contentSrcView];
}

#pragma mark ==========懒加载==========
- (NetEasyTabView *)indicatorView{
    if (!_indicatorView) {
        WS(ws);
        _indicatorView = [[NetEasyTabView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120*SCALEUNIT) titles:self.titleArr bgColor:[UIColor whiteColor] sliderColor:[UIColor colorWithHexString:@"#21d4a4"] clickBlock:^(NSInteger index, NSString *title) {
            [UIView animateWithDuration:0.30 animations:^{
                ws.contentSrcView.contentOffset = CGPointMake(CGRectGetWidth(ws.frame)*index, 0);
            }];
        }];
    }
    return _indicatorView;
}

#pragma mark ==========代理方法==========
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (scrollView.contentOffset.x/CGRectGetWidth(self.frame) == 0) {
        self.indicatorView.currentIndex = 0;
    } else if (scrollView.contentOffset.x/CGRectGetWidth(self.frame) == 1) {
        self.indicatorView.currentIndex = 1;
    } else {}
}



@end
